﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using WoBian.DA.Interface;
using System.Configuration;
using System.Data;
using Oracle.DataAccess.Client;
using WoBian.DA.Interface.Admin.SystemSettings;
namespace WoBian.DA
{
    public class DataAccessFactory
    {
        private static string ServerDbType 
        {
            get 
            {
                return System.Configuration.ConfigurationManager.AppSettings["DbType"];
            }
        }

        public static IDbConnection CreateDbConnection()
        {
            switch (ServerDbType)
            {
                case WoBian.Lib.ConstString.DbType.Oracle:
                    return new OracleConnection(WoBian.Lib.ConstString.ConnectionStringType.OracleConnectionString);
                default:
                    throw new Exception("未知的数据库类型!");
            }
        }

        public static IAdminUserDAL CreateAdminUserDAL(IDbConnection connection)
        {   
            switch (ServerDbType)
            {
                case WoBian.Lib.ConstString.DbType.Oracle:
                    return new WoBian.DA.Oracle.Admin.User.AdminUserDAL(connection);
                default:
                    throw new Exception("未知的数据库类型!");
            }
        }

        public static IDataAdapter CreateDataAdapter(IDbCommand cmd)
        {
            switch (ServerDbType)
            {
                case WoBian.Lib.ConstString.DbType.Oracle:
                    return new OracleDataAdapter(cmd as OracleCommand);
                default:
                    throw new Exception("未知的数据库类型!");
            }
        }

        public static ISystemSettingsDAL CreateSystemSettingsDAL(IDbConnection connection)
        {
            switch (ServerDbType)
            {
                case WoBian.Lib.ConstString.DbType.Oracle:
                    return new WoBian.DA.Oracle.Admin.SystemSettings.SystemSettingsDAL(connection);
                default:
                    throw new Exception("未知的数据库类型!");
            }
        }
    }
}
